<template>
	<view class="container">
		<Header title="助力明细"></Header>
		<view>
			<view class="integral-details">
			  <view class="header">
			    <view class="currentScore">当前积分：{{userInfo.availCredit}}</view>
			    <view class="line"></view>
			    <view class="nav acea-row">
			       <view class="item" style="width: 100%;">
			         <view>累计积分</view>
			         <view class="num">{{userInfo.totalCredit || 0}}</view>
			       </view>
			       <!-- <view class="item">
			         <view>累计消费</view>
			         <view class="num">{{userInfo.deduction_integral || 0}}</view>
			       </view>
			       <view class="item">
			         <view>今日获得</view>
			         <view class="num">{{userInfo.today_integral || 0}}</view>
			       </view> -->
			    </view>
			  </view>
			  <view class="wrapper">
			     <view class="list">
			        <view class="item acea-row row-between-wrapper" v-for="(item, index) in integralList" :key="index">
			           <view class="detail">
			              <view class="state">{{item.organizationName}}</view>
			              <view>{{item.createdAt}}</view>
			           </view>
			           <!-- <view class="num font-color" v-if="item.pm">+{{item.number}}</view>
			           <view class="num" v-else>-{{item.number}}</view> -->
					   <view class="num">{{item.donateCredit}}</view>
			        </view>
			        <view class="loadingicon acea-row row-center-wrapper">
						<text class="loading iconfont icon-jiazai" :hidden="loading==false"></text>{{loadTitle}}
					 </view>
			     </view>
			  </view>
			</view>
		</view>
	</view>
</template>

<script>	
	import Header from '@/subpages/components/header.vue'
	import {
		getUserInfo,
		getDonationIntegrallList
	} from '@/api/user.js'

	export default {
		components: {
			Header
		},
		data() {
			return {
				userInfo: {},
				integralList: [],
				loading: false,				
				loadTitle:'加载更多',
				loadend: false, // 加载到底部
				page: 1, // 页数
				pagesize: 10, // 每页条数
			}
		},
		onLoad() {
			this.getUserInfo().then(() => {
				this.getList();
			});
		},
		onReady() {
			
		},
		methods: {
			/**获取用户信息*/
			async getUserInfo() {
				const {data} = await getUserInfo();
				this.userInfo = data
			},
			/**获取数据*/
			async getList(isPage) {
				if (isPage) {
					this.loadend = false
					this.page = 1
					this.integralList = []
				}
				if (this.loading) return
				if (this.loadend) return
				this.loading = true
				this.loadTitle = ''
				uni.showLoading({
					title: '数据加载中...',
					mask: true
				});
				const query = {
					page: this.page,
					pagesize: this.pagesize
				}
				getDonationIntegrallList(query).then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						const list = res.data.lists
						this.loadend = list.length < this.pagesize
						this.integralList = [...this.integralList, ...list]
						this.loadTitle = this.loadend ? '我也是有底线的' : '加载更多'
						this.page++
					} else {
						uni.showToast({
							title: '获取数据失败！',
							duration: 1000,
							icon: 'none',
						});
					}
					this.loading = false
				});
				uni.hideLoading()
			}
		},
		/**
		   * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function () {
			this.getList();
		}
	}
</script>

<style lang="less" scoped>
	@import './integral.css';
	.header{
		margin-left: 0;
	}
</style>
